
// request函数
import getModifyData from '../../request-functions/getModifyData';
import refreshRequest from '../../components/AddNewPage/request/refresh';

export default async function(cb, pk_psnjob, refresh) {
    const {
        humanResourceOrganizationValue: {
            refpk
        },
        selectedRows,
        pageFrom
    } = this.state;

    let postData = {
        func_type: '1',
        pk_org: refpk,
        pk_psnjob: pk_psnjob ? pk_psnjob : selectedRows[0].data.values['pk_psnjob'].value
    };

    try {
        let res = null;
        
        if(refresh === 'refresh') {
            res = await refreshRequest(postData);

            if(res.success) {
                this.setState({
                    addPageTemplate: {
                        ...this.state.addPageTemplate,
                        ...res.data
                    }
                }, () => {
                    cb && cb.call(this);
                });
            }
        }
        else {
            res = await getModifyData(postData, pageFrom);
            
            if(res.success) {
                this.setState({
                    modifyData: res
                }, () => {
                    // 拿到修改页面的初始化数据之后，要经过处理
                    this.processEditPageTemplate(() => {
                        cb && cb.call(this);
                    });
                });
                
            }
        }
    }
    catch(e) {
    }
}